﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace com.superscene.util {
	/// <summary></summary>
	public class CycleCount {
		int nowCount = 0;
		//int initCount = 0;
		public int threshold = 0;
		bool isTriggerFirst = false;
		bool isFirst = true;

		public CycleCount(int _threshold) {
			threshold = _threshold;
		}

		public CycleCount(bool _isTriggerFirst, int _threshold) {
			threshold = _threshold;
			isTriggerFirst = _isTriggerFirst;
			//if(isMaxInit) {
			//	initCount = _threshold;
			//	nowCount = _threshold;
			//}
		}

		//public CycleCount(int _threshold, int _initCount) {
		//	threshold = _threshold;
		//	initCount = _initCount;
		//}

		/// <summary>重置计数</summary>
		public void reset() {
			reset(0);
		}

		/// <summary>重置计数</summary>
		public void reset(int value) {
			nowCount = value;
		}

		public void add(int value) {
			nowCount += value;
		}

		public void sub(int value) {
			nowCount -= value;
		}

		/// <summary>大于</summary>
		public bool gt() {
			if(isFirst && isTriggerFirst) {
				isFirst = false;
				return true;
			}
			return nowCount > threshold;
		}

		/// <summary>大于等于</summary>
		public bool egt() {
			if(isFirst && isTriggerFirst) {
				isFirst = false;
				return true;
			}
			return nowCount >= threshold;
		}

		/// <summary>小于</summary>
		public bool lt() {
			if(isFirst && isTriggerFirst) {
				isFirst = false;
				return true;
			}
			return nowCount < threshold;
		}

		/// <summary>小于等于</summary>
		public bool elt() {
			if(isFirst && isTriggerFirst) {
				isFirst = false;
				return true;
			}
			return nowCount <= threshold;
		}

	}
}
